package com.situ.mall.controller;

import cn.dsna.util.images.ValidateCode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * @ClassName ValidateCodeController
 * @Description TODO
 * @Author 周轩霆
 * @Date 2022/8/13 11:00
 **/

@Controller
@Slf4j
public class ValidateCodeController {

    @GetMapping("/getValidateCode")
    @ResponseBody
    public void getValidateCode(HttpServletResponse response, HttpSession session) throws IOException {
        //参数分别为验证码图片长、高，字符数、干扰线数
        ValidateCode validateCode = new ValidateCode(200, 40, 4, 50);
        validateCode.write(response.getOutputStream());
        //获取生成的验证码
        String validateCodeCode = validateCode.getCode();
        log.info("验证码是:" + validateCodeCode);
        session.setAttribute("validateCode", validateCodeCode);
    }

    @GetMapping("/login")
    public String login() {
        return "login";
    }
}
